package cn.stylefeng.guns.modular.tasks;

import cn.hutool.core.date.DateTime;
import cn.stylefeng.guns.core.timer.TimerTaskRunner;
import cn.stylefeng.guns.modular.entity.Reserved;
import cn.stylefeng.guns.modular.myenum.ReservedStatusEnum;
import cn.stylefeng.guns.modular.service.ReservedService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 未在规定时间签退记为违约
 *
 * @author 李宝嘉
 * @Date 2022/1/13 13:59
 */
@Component
public class QuitBreachTaskRunner implements TimerTaskRunner {
    @Resource
    private ReservedService reservedService;

    @Override
    public void action() {
        DateTime now = new DateTime();
        System.out.println(now);
        reservedService.lambdaUpdate().set(Reserved::getStatus, ReservedStatusEnum.BREACH)
                .apply("date_format(end_time,'%Y-%m-%d %H:%i')={0}",
                        now.toString("yyyy-MM-dd HH:mm"))
                .eq(Reserved::getStatus, ReservedStatusEnum.USE);
    }
}
